
package cn.edu.scau.cmi.hombio.service;

import cn.edu.scau.cmi.hombio.domain.PigHouse;
import cn.edu.scau.cmi.hombio.domain.Task;
import cn.edu.scau.cmi.hombio.domain.TaskPighouse;

import java.util.List;
import java.util.Set;

import org.junit.Test;

import org.junit.runner.RunWith;

import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.beans.factory.support.DefaultListableBeanFactory;

import org.springframework.context.ApplicationContext;

import org.springframework.mock.web.MockHttpServletRequest;

import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.TestExecutionListeners;

import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import org.springframework.test.context.support.DependencyInjectionTestExecutionListener;
import org.springframework.test.context.support.DirtiesContextTestExecutionListener;

import org.springframework.test.context.transaction.TransactionalTestExecutionListener;

import org.springframework.transaction.annotation.Transactional;

import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.RequestScope;
import org.springframework.web.context.request.ServletRequestAttributes;
import org.springframework.web.context.request.SessionScope;

/**
 * Class to run the service as a JUnit test. Each operation in the service is a separate test.
 *
 */

@RunWith(SpringJUnit4ClassRunner.class)
@TestExecutionListeners({
		DependencyInjectionTestExecutionListener.class,
		DirtiesContextTestExecutionListener.class,
		TransactionalTestExecutionListener.class })
@ContextConfiguration(locations = {
		"file:./resources/pigRs-security-context.xml",
		"file:./resources/pigRs-service-context.xml",
		"file:./resources/pigRs-dao-context.xml",
		"file:./resources/pigRs-web-context.xml" })
@Transactional
public class TaskPighouseServiceTest {

	/**
	 * The Spring application context.
	 *
	 */
	@SuppressWarnings("unused")
	private ApplicationContext context;

	/**
	 * The service being tested, injected by Spring.
	 *
	 */
	@Autowired
	protected TaskPighouseService service;

	/**
	 * Instantiates a new TaskPighouseServiceTest.
	 *
	 */
	public TaskPighouseServiceTest() {
		setupRequestContext();
	}

	/**
	 * Operation Unit Test
	* Delete an existing PigHouse entity
	* 
	 */
	@Test
	public void deleteTaskPighousePigHouse() {
		// TODO: JUnit - Populate test inputs for operation: deleteTaskPighousePigHouse 
		Integer taskpighouse_id = 0;
		Integer related_pighouse_id = 0;
		TaskPighouse response = null;
		response = service.deleteTaskPighousePigHouse(taskpighouse_id, related_pighouse_id);
		// TODO: JUnit - Add assertions to test outputs of operation: deleteTaskPighousePigHouse
	}

	/**
	 * Operation Unit Test
	* Delete an existing TaskPighouse entity
	* 
	 */
	@Test
	public void deleteTaskPighouse() {
		// TODO: JUnit - Populate test inputs for operation: deleteTaskPighouse 
		TaskPighouse taskpighouse = new cn.edu.scau.cmi.hombio.domain.TaskPighouse();
		service.deleteTaskPighouse(taskpighouse);
	}

	/**
	 * Operation Unit Test
	* Save an existing PigHouse entity
	* 
	 */
	@Test
	public void saveTaskPighousePigHouse() {
		// TODO: JUnit - Populate test inputs for operation: saveTaskPighousePigHouse 
		Integer id = 0;
		PigHouse related_pighouse = new cn.edu.scau.cmi.hombio.domain.PigHouse();
		TaskPighouse response = null;
		response = service.saveTaskPighousePigHouse(id, related_pighouse);
		// TODO: JUnit - Add assertions to test outputs of operation: saveTaskPighousePigHouse
	}

	/**
	 * Operation Unit Test
	* Delete an existing Task entity
	* 
	 */
	@Test
	public void deleteTaskPighouseTask() {
		// TODO: JUnit - Populate test inputs for operation: deleteTaskPighouseTask 
		Integer taskpighouse_id_1 = 0;
		Integer related_task_id = 0;
		TaskPighouse response = null;
		response = service.deleteTaskPighouseTask(taskpighouse_id_1, related_task_id);
		// TODO: JUnit - Add assertions to test outputs of operation: deleteTaskPighouseTask
	}

	/**
	 * Operation Unit Test
	* Return a count of all TaskPighouse entity
	* 
	 */
	@Test
	public void countTaskPighouses() {
		Integer response = null;
		response = service.countTaskPighouses();
		// TODO: JUnit - Add assertions to test outputs of operation: countTaskPighouses
	}

	/**
	 * Operation Unit Test
	 */
	@Test
	public void findTaskPighouseByPrimaryKey() {
		// TODO: JUnit - Populate test inputs for operation: findTaskPighouseByPrimaryKey 
		Integer id_1 = 0;
		TaskPighouse response = null;
		response = service.findTaskPighouseByPrimaryKey(id_1);
		// TODO: JUnit - Add assertions to test outputs of operation: findTaskPighouseByPrimaryKey
	}

	/**
	 * Operation Unit Test
	* Save an existing TaskPighouse entity
	* 
	 */
	@Test
	public void saveTaskPighouse() {
		// TODO: JUnit - Populate test inputs for operation: saveTaskPighouse 
		TaskPighouse taskpighouse_1 = new cn.edu.scau.cmi.hombio.domain.TaskPighouse();
		service.saveTaskPighouse(taskpighouse_1);
	}

	/**
	 * Operation Unit Test
	* Load an existing TaskPighouse entity
	* 
	 */
	@Test
	public void loadTaskPighouses() {
		Set<TaskPighouse> response = null;
		response = service.loadTaskPighouses();
		// TODO: JUnit - Add assertions to test outputs of operation: loadTaskPighouses
	}

	/**
	 * Operation Unit Test
	* Save an existing Task entity
	* 
	 */
	@Test
	public void saveTaskPighouseTask() {
		// TODO: JUnit - Populate test inputs for operation: saveTaskPighouseTask 
		Integer id_2 = 0;
		Task related_task = new cn.edu.scau.cmi.hombio.domain.Task();
		TaskPighouse response = null;
		response = service.saveTaskPighouseTask(id_2, related_task);
		// TODO: JUnit - Add assertions to test outputs of operation: saveTaskPighouseTask
	}

	/**
	 * Operation Unit Test
	* Return all TaskPighouse entity
	* 
	 */
	@Test
	public void findAllTaskPighouses() {
		// TODO: JUnit - Populate test inputs for operation: findAllTaskPighouses 
		Integer startResult = 0;
		Integer maxRows = 0;
		List<TaskPighouse> response = null;
		response = service.findAllTaskPighouses(startResult, maxRows);
		// TODO: JUnit - Add assertions to test outputs of operation: findAllTaskPighouses
	}

	/**
	 * Autowired to set the Spring application context.
	 *
	 */
	@Autowired
	public void setContext(ApplicationContext context) {
		this.context = context;
		((DefaultListableBeanFactory) context.getAutowireCapableBeanFactory()).registerScope("session", new SessionScope());
		((DefaultListableBeanFactory) context.getAutowireCapableBeanFactory()).registerScope("request", new RequestScope());
	}

	/**
	 * Sets Up the Request context
	 *
	 */
	private void setupRequestContext() {
		MockHttpServletRequest request = new MockHttpServletRequest();
		ServletRequestAttributes attributes = new ServletRequestAttributes(request);
		RequestContextHolder.setRequestAttributes(attributes);
	}
}
